package com.sy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sy.dto.CoursePageQueryDTO;
import com.sy.dto.CoursedetailPageQueryDTO;
import com.sy.mapper.CourseMapper;
import com.sy.mapper.CoursedetailMapper;
import com.sy.pojo.Course;
import com.sy.pojo.Coursedetail;
import com.sy.result.PageResult;
import com.sy.service.CourseService;
import com.sy.service.CoursedetailService;
import com.sy.vo.CourseVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class CoursedetailServiceImpl
        extends ServiceImpl<CoursedetailMapper, Coursedetail> implements CoursedetailService {

    @Autowired
    private CoursedetailMapper coursedetailMapper;

    /**
     * 课程明细分页查询
     * @param coursedetailPageQueryDTO
     * @return
     */
    @Override
    public PageResult findAll(CoursedetailPageQueryDTO coursedetailPageQueryDTO) {
        Page<Coursedetail> page = new Page<>(coursedetailPageQueryDTO.getPage(),
                coursedetailPageQueryDTO.getPageSize());
        // 条件构造器
        LambdaQueryWrapper<Coursedetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Coursedetail::getCid, coursedetailPageQueryDTO.getCid())
        // 排序 根据排序号进行升序排序, 如果排序号一样的情况下, 根据时间进行升序排序
                .orderByAsc(Coursedetail::getSort, Coursedetail::getCreateTime);
        page = this.page(page, queryWrapper);
        return new PageResult(page.getTotal(), page.getRecords());
    }
}
